{template live_header}
<link rel="stylesheet" href="static/calendar/js/calendar.css" />
<script type="text/javascript" charset="utf-8" src="static/calendar/calendar.php"></script>

<link rel="stylesheet" href="/static/kindeditor/themes/default/default.css" />
<script charset="utf-8" src="/static/kindeditor/kindeditor-min.js"></script>
<script charset="utf-8" src="/static/kindeditor/lang/zh_CN.js"></script>

<style type="text/css">
    .bg{display:none;position:fixed;width:100%;height:100%;background:#000;z-index:2;top:0;left:0;opacity:0.7;}
</style>
<h4 style="padding-left:10px;;">
    <a href="?c=live_admin&a=getList"><span>微课列表</span></a>
    >>
    {if $liveId>0}
        <a href="?c=live_admin&a=addLive&liveId={$liveId}"><span>编辑微课</span></a>
    {else}
        <a href="?c=live_admin&a=addLive"><span>新增微课</span></a>
    {/if}
</h4>
<script type="text/javascript">
    function uploadImage() {
        if($("#imgFile").val() != '') $("#upload_form").submit();
    }
    function upload_frame_load() {
        var data = $(window.frames['upload_frame'].document.body).html();
        if(data) {
            data = eval('(' + data + ')');
            //console.log(data);return false;
            if(data.status=='ok'){
                var _this= $('#showImage');_num = _this.find('img').length;
                var _html = '';
                if (_num && (_num % 5) == 0) {
                    _html +='<br />';
                }
                 _html +=
                        '<span style="margin: 10px  10px 10px 10px">'
                        +'<img src="'+ data.image+'" style="width: 100px;height: 100px;">'
                        +'<input type="hidden" name="image[]" value="'+data.image+'" />'
                        +'</span>'
                        +'<span class="btn btn-primary delimages" >删除</span>';

                $('#showImage').html(_html);
            }else{
                alert(data.error_msg);
            }
        }
    }

    $(function () {
        KindEditor.ready(function (K) {
            K.create('textarea[name="content"]', {
                allowFileManager: true,
                uploadJson: './index.php?c=admin&a=uploadKindEditorImg',
                newlineTag: 'p',
                filterMode: true,
                htmlTags: {
                    p: ['style', 'color', 'align', 'class'],
                    font: ['style', 'color', 'size', 'face', 'class'],
                    span: ['style', 'style', 'color', 'align'],
                    div: ['style', 'class', 'align'],
                    a: ['style', 'class', 'href', 'target', 'name'],
                    embed: ['style', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality',
                        'style', 'align', 'allowscriptaccess', '/'],
                    img: ['style', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', 'style', 'data-source', '/', 'class'],
                    hr: ['style', 'class', '/'],
                    br: ['/'],
                    'ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6': ['style', 'align'],
                    'tbody,tr,strong,b,sub,sup,em,i,u,strike,section': ['style', 'class'],
                },
                afterBlur: function () {
                    this.sync();
                }
            });
            K.create('textarea[name="introduce2"]', {
                allowFileManager: true,
                uploadJson: './index.php?c=admin&a=uploadKindEditorImg',
                newlineTag: 'p',
                filterMode: true,
                htmlTags: {
                    p: ['style', 'color', 'align', 'class'],
                    font: ['style', 'color', 'size', 'face', 'class'],
                    span: ['style', 'style', 'color', 'align'],
                    div: ['style', 'class', 'align'],
                    a: ['style', 'class', 'href', 'target', 'name'],
                    embed: ['style', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality',
                        'style', 'align', 'allowscriptaccess', '/'],
                    img: ['style', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', 'style', 'data-source', '/', 'class'],
                    hr: ['style', 'class', '/'],
                    br: ['/'],
                    'ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6': ['style', 'align'],
                    'tbody,tr,strong,b,sub,sup,em,i,u,strike,section': ['style', 'class'],
                },
                afterBlur: function () {
                    this.sync();
                }
            });
        });
    })

</script>
<div id="fream">
    <form id="upload_form" method="post" action="?c=live_admin&a=ajaxUploadImage" target="upload_frame" enctype="multipart/form-data">
        <input type="file" name="imgFile" id="imgFile" style="display:none;" onchange="uploadImage();">
    </form>
    <iframe id="upload_frame" name="upload_frame" style="display:none" onLoad="upload_frame_load();"></iframe>
</div>
<form class="form-horizontal"  action="?c=live_admin&a=ajaxAddLive"  id="tr_form">
    <div class="control-group">
        <label class="control-label" >微课标题：</label>
        <div class="controls">
            {if  isset($info['title'])}
            <input type="text" value="{if isset($info['title'])}{$info['title']}{/if}" name="title" readonly="readonly" placeholder="请输入标题" />
            {else}
            <input type="text" value="{if isset($info['title'])}{$info['title']}{/if}" name="title" placeholder="请输入标题" />
            {/if}
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" >  缩略图：</label>
        <div class="controls">
            <button type="button" id="file_upload_btn" class="btn btn-primary" onclick="$('#imgFile').trigger('click')">
                <i class="ace-icon fa fa-cloud-upload bigger-110"></i>上传图片
            </button>
        </div>
    </div>
    <div class="control-group">
        <div class="controls" id="showImage">
            {if isset($info['image_url'])}
            <span style="margin: 10px  10px 10px 10px">
             <img src="{$info['image_url']}" style="width: 100px;height: 100px;">
             <input type="hidden" name="image[]" value="{$info['image_url']}" />
            </span>
            <span class="btn btn-primary delimages" >删除</span>
            {/if}
        </div>
    </div>

    <div class="control-group">
        <label class="control-label" >报名费：</label>
        <div class="controls">
            <input type="text" value="{if isset($info['price'])}{$info['price']}{/if}" name="price" placeholder="请输入报名费，最多2位小数" />
        </div>
    </div>

    <div class="control-group">
        <label class="control-label" >提问价格：</label>
        <div class="controls">
            <input type="text" value="{if isset($info['question_gold_num'])}{$info['question_gold_num']}{/if}" name="quesGoldNum" placeholder="请输入0~100小元宝整数" />
        </div>
    </div>

    <div class="control-group">
        <label class="control-label" >限制人数：</label>
        <div class="controls">
            <input type="text" value="{if isset($info['limit_num'])}{$info['limit_num']}{/if}" name="limitNum" placeholder="不填或为0代表不限制" />
        </div>
    </div>

    <div class="control-group">
        <label class="control-label" >开始时间：</label>
        <div class="controls">
            <input type="text" name="startTime" id="date_time_id" value="{if isset($info['formatStartTime'])}{$info['formatStartTime']}{/if}" readonly="readonly" placeholder="开始时间">　
            <button name="date_time_btn" type="button" id="date_time_btn" onclick="return showCalendar('date_time_id', '%Y-%m-%d %H:%M:%S', '24', false, 'date_time_btn');" class="button" id="date_time_id"/>选择</button>
        </div>
    </div>

    <div class="control-group">
        <label class="control-label" >主讲人：</label>
        <div class="controls">
            <input type="text" value="{if isset($info['speaker_id'])}{$info['speaker_id']}{/if}" name="speakerId" placeholder="请输入主讲人UID" />
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" >微课详情：</label>
        <div class="controls">
             <textarea rows="10" name="content" style="width:800px; min-height:200x;">
                {if isset($info['content'])}{$info['content']}{/if}
            </textarea>
        </div>
    </div>
    <div class="control-group">
        <div class="controls">
            <input type="hidden" name="liveId" value="{$liveId}"/>
            <span class="btn btn-primary" type="button" id="qd">确定</span>
        </div>
    </div>
</form>
{template footer}
<script type="text/javascript">
    $(document).on("click",".delimages", function () {
        var _this=$(this),_del = $(this).prev('span');
        _del.remove();
        _this.remove();
    })

    $('#qd').on('click',function(){
        $.ajax({
            type:'POST',
            url:$('#tr_form').attr('action'),
            data:$('#tr_form').serialize(),
            dataType:'json',
            success:function(d){
                if(d.status=='ok'){
                    alert(d.error_msg);
                    window.location.href=d.url;
                }else{
                    alert(d.error_msg);
                }
            }
        })
    })
</script>